home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 2
/
Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso
/
Aminet
/
misc
/
amag
/
sh9301c.lha
/
Komprimieren(S.89)
/
Huffman-Codes.asm
next >
Wrap
Assembly Source File
|
1993-01-12
|
3KB
|
215 lines
lea a,a1 ; Anfangsadresse der Quelldatei
lea ziel,a2 ; Anfangsadresse der Zieldatei
move.l #aend-a,d7 ; Quelldateilänge
jsr Pack
lea ziel,a0 ; Anfangsadresse der komprimierten Datei
lea a,a5 ; Anfangsadresse der Zieldatei
jsr Unpack
rts
a: incbin "Programmname" ; zu komprimierendes Programm
aend:
Pack:
move.l d7,-(sp)
move.l a1,-(sp)
move.l a2,-(sp)
lea count(pc),a0
subq.l #1,d7
Anzahl: moveq #0,d0
move.b (a1,d7.l),d0
add.w d0,d0
add.w d0,d0
addq.l #1,(a0,d0.w)
dbra d7,Anzahl
moveq #0,d0
move.l d0,d7
move.l a0,a2
lea heap(pc),a3
Loop2: tst.l (a2)+
beq.s Loop
addq.w #2,d0
move.w d7,(a3)+
Loop: addq.w #4,d7
cmp.w #$400,d7
bne.s Loop2
lea heap(pc),a3
move.l d0,d6
move.l d0,d1
lsr.w #1,d1
down: move.w d6,d7
move.w -2(a3,d7.w),d2
bsr downheap
subq.w #2,d6
bne.s down
lea dad(pc),a4
repeat: move.w (a3),d6
move.w -2(a3,d0.w),(a3)
subq.w #2,d0
moveq #2,d7
move.l d0,d1
lsr.w #1,d1
move.w (a3),d2
bsr downheap
move.w (a3),d2
move.l (a0,d2.w),d3
add.l (a0,d6.w),d3
move.l d0,d7
add.l d7,d7
move.l d3,-4(a2,d7.w)
add.l #$3fc,d7
move.l d7,(a4,d6.w)
move.w d7,(a3)
neg.l d7
move.l d7,(a4,d2.w)
moveq #2,d7
move.w (a3),d2
bsr downheap
cmp.w #2,d0
bne.s repeat
clr.l $400(a4)
lea code(pc),a2
lea len(pc),a3
moveq #0,d7
for: moveq #-1,d0
tst.l (a0)+
bne.s Weiter2
clr.w (a2)+
move.b d0,(a3)+
bra.s next
Weiter2:moveq #1,d1
moveq #0,d3
move.l (a4,d7.w),d2
repeat2:bge.s ben
add.l d1,d3
neg.l d2
ben: add.l d1,d1
addq.l #1,d0
move.l (a4,d2.w),d2
bne.s repeat2
move.w d3,(a2)+
move.b d0,(a3)+
next: addq.w #4,d7
cmp.w #$400,d7
bne.s for
move.l (sp)+,a0
move.l (sp)+,a2
add.l (sp)+,a2
lea len(pc),a3
lea code(pc),a4
moveq #0,d7
move.l d7,d0
move.l d7,d6
move.l d7,d2
for2: moveq #0,d0
move.b (a1)+,d0
moveq #0,d1
move.b (a3,d0.w),d1
add.w d0,d0
lea 1(a4,d0.w),a5
rueck: cmp.b #8,d1
blt.s rueck2
move.b d1,d2
subq.b #8,d2
btst d2,-1(a5)
bra.s wtw
rueck2: btst d1,(a5)
wtw: beq.s wt
bset d7,(a0)
wt: addq.l #1,d6
addq.b #1,d7
and.b #7,d7
bne.s wet
addq.l #1,a0
wet: dbf d1,rueck
cmp.l a1,a2
bne.s for2
subq.l #1,d6
lea length(pc),a0
move.l d6,(a0)
rts
downheap:
cmp.w d1,d7
bgt.s Weiter
move.l d7,d3
add.w d3,d3
cmp.w d0,d3
bge.s Sprung
lea -2(a3,d3.w),a5
move.w (a5)+,d4
move.w (a5),d5
move.l (a0,d5.w),d5
cmp.l (a0,d4.w),d5
bge.s Sprung
addq.w #2,d3
Sprung: move.w -2(a3,d3.w),d4
move.l (a0,d4.w),d5
cmp.l (a0,d2.w),d5
bgt.s Weiter
move.w d4,-2(a3,d7.w)
move.w d3,d7
bra.s downheap
Weiter: move.w d2,-2(a3,d7.w)
rts
heap: dcb.w 256,0
count: dcb.l 2*256,0
dad: dcb.l 2*256,0
Unpack:
move.l length(pc),d4 ; komprimierte Dateilänge in Bits
lea code(pc),a3
moveq #0,d0
move.l d0,d6
move.l d0,d5
re: btst d6,(a0)
beq.s nicht
addq.b #1,d0
nicht: addq.b #1,d6
and.b #7,d6
bne.s nicht2
addq.l #1,a0
nicht2: moveq #0,d7
lea len(pc),a2
ll: cmp.b (a2)+,d5
bne.s l2
move.w d7,d1
add.w d1,d1
cmp.w (a3,d1.w),d0
bne.s l2
moveq #0,d0
move.b #-1,d5
move.b d7,(a5)+
move.b d5,d7
l2: addq.b #1,d7
bne.s ll
add.w d0,d0
addq.b #1,d5
dbf d4,re
rts
length: dc.l 0 ; komprimiertes Programm
code: dcb.w 256,0
len: dcb.b 256,0
ziel: dcb.b aend-a,0